package data_structure;

import java.util.LinkedList;

public class leetcode_0111 {
    public int minDepth(TreeNode root) {
        LinkedList<TreeNode> queue=new LinkedList<>();
        LinkedList<TreeNode> list=new LinkedList<>();
        if(root==null) return 0;
        LinkedList<Integer> num=new LinkedList<>();
        queue.add(root);
        num.add(0);
        int current=0;
        while(!queue.isEmpty()){
            TreeNode node=queue.getFirst();
            queue.removeFirst();
            int number=num.getFirst();
            num.removeFirst();
            if(node.left!=null){
                queue.add(node.left);
                num.add(number+1);
            }
            if(node.right!=null){
                queue.add(node.right);
                num.add(number+1);
            }
            if(node.left==null&&node.right==null) return number+1;
        }
        return 0;
    }
}
